/**
 * 背景层
 * @namespace Note.BackgroundLayer
 * 
 * Note.BackgroundLayer类继承自抽象接口
 * interface Layer{
 * 		void load(data);
 * 		array save();
 * 		void clear();
 * }
 * 
 * 构造函数
 * 
 * @constructor BackgroundLayer
 * @author JunEnstein 2017-05-18
 * @param Object canvas canvas元素对象
 */
Note.BackgroundLayer = function(canvas){
	// canvas元素对象
	this._canvas = canvas;
	// 获取绘图句柄
	this._context = canvas.getContext("2d");
};

/**
 * 背景层初始化
 * @method initialize
 * @author JunEnstein 2017-05-19
 * @param  Image img 背景图片
 */
Note.BackgroundLayer.prototype.initialize = function(img){
	var self = this;
	img.onload = function(){
		self.clear();
		self._context.drawImage(img, 0, 0, self._canvas.width, self._canvas.height);
	};
};

/**
 * 载入data数据到对象中
 * @method load
 * @author JunEnstein 2017-05-19
 * @param  Image data 恢复到背景层的图片数据
 */
Note.BackgroundLayer.prototype.load = function(data){
	this.initialize(data);
};

/**
 * 保存对象数据
 * @method save
 * @author JunEnstein 2017-05-19
 * @return Image 背景层的图片数据
 */
Note.BackgroundLayer.prototype.save = function(){
	return this._canvas.toDataURL("image/png");
};

/**
 * 将缓冲层和背景层压成一张图片
 * @method compress
 * @author yeweiyang 2018-01-09
 * @param  Image img 缓冲层图片图片
 */
Note.BackgroundLayer.prototype.compress = function(cacheImg){
	this._context.drawImage(cacheImg, 0, 0, this._canvas.width, this._canvas.height);
};

/**
 * 清空信息
 * @method clear
 * @author JunEnstein 2017-05-19
 */
Note.BackgroundLayer.prototype.clear = function(){
	this._context.clearRect(0, 0, this._canvas.width, this._canvas.height);
};